package qf.wlh.com.oneprisdent.adapter;

import android.content.Context;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import bean.SpeakerListViewBean;
import qf.wlh.com.oneprisdent.R;

/**
 * Created by zyq on 2016/11/28.
 */

//我是
public class SpeakerListViewAdapter extends BaseAdapter {
    private List<SpeakerListViewBean.DataBean> data;
    private Context context;

    public SpeakerListViewAdapter(List<SpeakerListViewBean.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data!=null?data.size():0;
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    //计算高度
    public int dip2px(float dip) {
        float v = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics());
        return (int) (v );
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view==null) {
            view = LayoutInflater.from(context).inflate(R.layout.speakerlistviewitem, null);


            holder=new ViewHolder();
            holder.image= (ImageView) view.findViewById(R.id.image);
            holder.textTitle= (TextView) view.findViewById(R.id.texttitle);
            holder.textNmae= (TextView) view.findViewById(R.id.textname);
            holder.textCmtnum= (TextView) view.findViewById(R.id.time);
            holder.textLikenum= (TextView) view.findViewById(R.id.play_time);
            holder.textViewnum= (TextView) view.findViewById(R.id.text_like);
            holder.textTime= (TextView) view.findViewById(R.id.text_reviewtime);
            ///////////////////////////////////
            ViewGroup.LayoutParams layoutParams = holder.image.getLayoutParams();
            layoutParams.height = dip2px(100);
            holder.image.setLayoutParams(layoutParams);
            ////////////////////////////////

            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.textTitle.setText(data.get(i).getTitle());
        holder.textNmae.setText(data.get(i).getLecturer().getNickname());
        holder.textCmtnum.setText(data.get(i).getTime());
        holder.textLikenum.setText(data.get(i).getLikenum());
        holder.textViewnum.setText(data.get(i).getViewnum());
        holder.textTime.setText(data.get(i).getCmtnum());
        Picasso.with(context).load(data.get(i).getCover()).into(holder.image);
        return view;
    }
    class ViewHolder{
        ImageView image;
        TextView textTitle,textViewnum,textLikenum,textCmtnum,textNmae,textTime;
    }
}
